package com.mall.service;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.db.api.CmsSubjectApi;
import com.mall.pageResult.PageResult;
import com.mall.pojo.CmsSubject;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CmsSubjectService {

    @DubboReference
    private CmsSubjectApi cmsSubjectApi;

    //获取全部商品专题
    public List<CmsSubject> listAll() {
        return cmsSubjectApi.listAll();
    }

    /**
     * 根据专题名称分页获取商品专题
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    public PageResult<CmsSubject> list(Integer pageNum, Integer pageSize, String keyword) {
        Page<CmsSubject> page = cmsSubjectApi.list(pageNum,pageSize,keyword);
        //组装返回结果数据
        PageResult<CmsSubject> result = new PageResult<>();
        result.setPageNum(pageNum);
        result.setPageSize(pageSize);
        result.setList(page.getRecords());
        result.setTotal(Convert.toInt(page.getTotal()));
        result.setTotalPage(Convert.toInt(page.getPages()));
        return result;
    }
}
